<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>js对象_Array</title>
</head>
<body>
    
</body>
<script>
    //Array
    //String
    //JSON
    //DOM
    //BOM

    //Array类似c语言,长度可变类型可变，未定义部分显示未undefined
    var array_1 = new Array([1,2,3,4])
    var array_2 = [1,2,3,4,5]
    array_2[10] = "hello"
    console.log(array_1)
    console.log(array_2)
    console.log(array_2[8])
    console.log(array_2[10])

    //数组属性length获取长度
    console.log(array_2.length)

    //方法
    //forEach() 遍历数组
    //push() 尾部添加元素
    //splice() 删除元素

    //for循环遍历
    for(let i = 0; i<array_2.length ; i++){
        console.log(array_2[i]);
    }

    //forEach() ---仅遍历有值的元素
    array_2.forEach(function(e){
        console.log(e);
    })
    
    //ES6箭头函数 (...)=>{}
    /******类似lamada表达式****/
    array_2.forEach((e)=>{
        console.log(e);
    })

    //push方法
    array_1.push(8,9,10);
    array_2.push(8,9,10);
    console.log(array_1);
    console.log(array_2);

    //splice---空元素也会被删除，指定删除起始位置，和删除个数
    array_2.splice(2,5);
    console.log(array_2);
</script>
</html>